#pragma once

#include "xtask.h"
#include <event2/event.h>
#include <event2/bufferevent.h>
#include <string>

class XFtpTask: public XTask {
public:

	std::string curDir = "/";
	std::string rootDir = ".";
	// PORT 数据通道的IP和端口
	std::string ip = "";
	int port = 0;

	// 命令通道
	XFtpTask *cmdTask = nullptr;

	// 解析协议
	virtual void Parse(std::string type, std::string msg) {}

	// 回复cmd消息
	void ResCmd(std::string msg);

	// 连接数据通道
	void ConnectPort();

	// 用来发送建立了连接的数据通道
	void Send(std::string data);
	void Send(const char *data, int datasize);

	virtual void Close();

	virtual void Read(struct bufferevent *bev) {}
	virtual void Write(struct bufferevent *bev) {}
	virtual void Event(struct bufferevent *bev, short what) {}
	virtual bool Init() { return true; }

	void SetCallback(struct bufferevent *bev);
protected:
	static void ReadCB(bufferevent *bev, void *arg);
	static void WriteCB(bufferevent *bev, void *arg);
	static void EventCB(bufferevent *bev, short what, void *arg);
	// 命令bev
	struct bufferevent *bev = nullptr;
    FILE *fp = nullptr;
};

